<?php
class Bbling_Model_Collection_Abstract extends Evebit_Model_Mysql_Collection{
	
	public function _initSelect(){
		$this->getSelect()->from(array('main_table'=>'business'));
		$this->initJoin();
		
		return $this;
	}
	
	public function initJoin(){
		$companyEntity = new Bbling_Model_Entity_Company();
		$companyFields = $companyEntity->getResource()->getTableFields();
		
		$financialEntity = new Bbling_Model_Entity_Financial();
		$financailFields = $financialEntity->getResource()->getTableFields();
		
		$marketingEntity = new Bbling_Model_Entity_Marketing();
		$marketingFields = $marketingEntity->getResource()->getTableFields();
		
		$productEntity = new Bbling_Model_Entity_Product();
		$productFields = $productEntity->getResource()->getTableFields();
		
		$userEntity = new User_Model_Entity_User();
		$userFields = $userEntity->getResource()->getTableFields();
		
		$this->getSelect()->join(array('company_table'=>'company'), 'main_table.company_id = company_table.id', $companyFields);
		$this->getSelect()->join(array('financial_table'=>'financial'), 'main_table.financial_id = financial_table.id', $financailFields);
		$this->getSelect()->join(array('marketing_table'=>'marketing'), 'main_table.marketing_id = marketing_table.id', $marketingFields);
		$this->getSelect()->join(array('product_table'=>'product'), 'main_table.product_id = product_table.id', $productFields);
		$this->getSelect()->join(array('user_table'=>'user'), 'main_table.user_id = user_table.id', $userFields);
		
		return $this;
	}
	
}